package com.lzx.iteam.provider;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.lzx.iteam.provider.CloudContactsDB.CloudGroupDbo;
import com.lzx.iteam.provider.CloudContactsDB.CommunicationRule;
import com.lzx.iteam.provider.CloudContactsDB.*;
import com.lzx.iteam.util.PreferenceUtil;

/**
 * Created by hfx_lk on 14-12-23.
 */
public class CloudContactsDBHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "clouddialer.db";
    private static final int DATABASE_VERSION = 19;
    private PreferenceUtil mPreferenceUtil;
    private static final String CREATE_CLOUD_GROUP =
            "CREATE TABLE IF NOT EXISTS "
                    + CloudGroupDbo.TABLE_NAME + " ("
                    + CloudGroupDbo._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                    + CloudGroupDbo.GROUP_ID + " INTEGER NOT NULL, "
                    + CloudGroupDbo.GROUP_NAME + " TEXT, "
                    + CloudGroupDbo.GROUP_TYPE + " INTEGER DEFAULT 0, "
                    + CloudGroupDbo.CONTACT_ID + " TEXT, "
                    + CloudGroupDbo.CONTACT_COUNT + " INTEGER DEFAULT 0, "
                    + CloudGroupDbo.MEMBER_COUNT + " INTEGER DEFAULT 0, "
                    + CloudGroupDbo.GROUP_IMG + " TEXT, "
                    + CloudGroupDbo.UPDATE_TIME + " INTEGER DEFAULT 0,"
                  + CloudGroupDbo.IS_NEW + " TEXT,"
                  + CloudGroupDbo.HAS_TAGS + " TEXT,"
                  + CloudGroupDbo.CREATOR_UID + " TEXT,"
                  + CloudGroupDbo.USER_TYPE + " TEXT);";

    /**
     * 黑名单
     */
    private static final String CREATE_BLACKLIST_TABLE =
            "CREATE TABLE IF NOT EXISTS " + CommunicationRule.TABLE_NAME + " ("
                    + CommunicationRule._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                    + CommunicationRule.PHONE_NUMBER + " TEXT NOT NULL, "
                    + CommunicationRule.CONTACT_NAME + " TEXT, "
                    + CommunicationRule.PATTERN + " INTEGER NOT NULL, "
                    + CommunicationRule.CONTACT_ID + " INTEGER "
                    + ");";
    /**
     * 我的状态
     */
    private static final String CREATE_STATEDATA = "CREATE TABLE IF NOT EXISTS "
            +
            StateData.TABLE_NAME + " (" + StateData.STATE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + StateData.STATE_TEXT + " TEXT NOT NULL" + ");";

    /**
     * 小组
     */
    private static final String CREATE_CHAT_GROUP = "CREATE TABLE IF NOT EXISTS " +
            ChatGroupData.TABLE_NAME + " (" + ChatGroupData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + ChatGroupData.CHAT_GROUP_ID + " TEXT NOT NULL, "
            + ChatGroupData.CHAT_GROUP_NAME + " TEXT NOT NULL, "
            + ChatGroupData.CHAT_GROUP_IMG + " TEXT NOT NULL, "
            + ChatGroupData.LAST_UPDATE_TIME + " TEXT ,"
            + ChatGroupData.LAST_MSG_NAME + " TEXT,"
            + ChatGroupData.LAST_MSG_CONTENT + " TEXT,"
            + ChatGroupData.USER_TYPE + " TEXT,"
            + ChatGroupData.CREATOR_NAME + " TEXT,"
//            + ChatGroupData.UN_REGISTERED + " TEXT,"
            + ChatGroupData.IS_NEW + " TEXT,"
            + ChatGroupData.UNREAD_COUNT + " TEXT,"
            + ChatGroupData.MEMBER_COUNT + " TEXT,"
            + ChatGroupData.TYPE + " TEXT,"
            + ChatGroupData.IS_ACTIVE + " TEXT"
            + ");";

    /**
     * 事件
     */
    private static final String CREATE_EVENT = "CREATE TABLE IF NOT EXISTS " +
            EventData.TABLE_NAME + " (" + EventData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + EventData.EVENT_ID + " TEXT NOT NULL, "
            + EventData.EVENT_TYPE + " TEXT NOT NULL, "
            + EventData.EVENT_NAME + " TEXT ,"
            + EventData.UPDATE_TIME + " TEXT ,"
            + EventData.USER_TYPE + " TEXT,"
            + EventData.HAS_READ + " TEXT,"
            + EventData.CREATE_TIME + " TEXT,"
            + EventData.USER_ID + " TEXT,"
            + EventData.USER_NAME + " TEXT,"
            + EventData.MEMBER_COUNT + " TEXT,"
            + EventData.EVENT_TITLE + " TEXT,"
            + EventData.CONTENT1 + " TEXT,"
            + EventData.INIT_TITLE1 + " TEXT,"
            + EventData.URL1 + " TEXT,"
            + EventData.CONTENT2 + " TEXT,"
            + EventData.INIT_TITLE2 + " TEXT,"
            + EventData.URL2 + " TEXT,"
            + EventData.CONTENT3 + " TEXT,"
            + EventData.INIT_TITLE3 + " TEXT,"
            + EventData.URL3 + " TEXT,"
            + EventData.HAS_READ_COUNT + " TEXT,"
            + EventData.ATTACHMENT_THUMB_IMAGE + " TEXT,"
            + EventData.ATTACHMENT_ORI_IMAGE + " TEXT,"
            + EventData.ATTACHMENT_VOICE + " TEXT,"
            + EventData.ATTACHMENT_FILE + " TEXT,"
            + EventData.REPLY_COUNT + " TEXT,"
            + EventData.RECEIVER + " TEXT,"
            + EventData.AUTHOR + " TEXT,"
            + EventData.EVENT_AVATAR + " TEXT,"
            + EventData.ACTIVITY_TIME + " TEXT,"
            + EventData.END_TIME + " TEXT,"
            + EventData.ACTIVITY_SITE + " TEXT,"
            + EventData.JOIN_COUNT + " TEXT,"
            + EventData.HAS_JOIN + " TEXT,"
            + EventData.VOTES + " TEXT,"
            + EventData.VOTE_NUMBER + " TEXT,"
            + EventData.IS_QRCODE + " TEXT,"
            + EventData.QRCODE + " TEXT,"
            + EventData.MY_USERID + " TEXT,"
            + EventData.REPLY_LAST_NAME + " TEXT,"
            + EventData.REPLY_LAST_CONTENT + " TEXT,"
            + EventData.UNREAD_COUNT + " TEXT"
            + ");";

    /**
     * 事件模板
     */
    private static final String CREATE_EVENT_MODEL = "CREATE TABLE IF NOT EXISTS " +
            EventModelData.TABLE_NAME + " (" + EventModelData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + EventModelData.USER_ID + " TEXT,"
            + EventModelData.EVENT_ID + " TEXT, "
            + EventModelData.EVENT_TYPE + " TEXT , "
            + EventModelData.EVENT_TYPE_NAME + " TEXT , "
            + EventModelData.EVENT_TITLE + " TEXT,"
            + EventModelData.EVENT_RECEIVER + " TEXT,"
            + EventModelData.EVENT_TIME + " TEXT,"
            + EventModelData.CONTENT1 + " TEXT,"
            + EventModelData.INIT_TITLE1 + " TEXT,"
            + EventModelData.CONTENT2 + " TEXT,"
            + EventModelData.INIT_TITLE2 + " TEXT,"
            + EventModelData.CONTENT3 + " TEXT,"
            + EventModelData.INIT_TITLE3 + " TEXT,"
            + EventModelData.ATTACHMENT_THUMB_IMAGE + " TEXT,"
            + EventModelData.ATTACHMENT_ORI_IMAGE + " TEXT"
            + ");";

    /**
     * 创建事件草稿
     */
    private static final String CREATE_EVENT_DRAFTS = "CREATE TABLE IF NOT EXISTS " +
            EventDraftsData.TABLE_NAME + " (" + EventModelData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + EventDraftsData.USER_ID + " TEXT,"
            + EventDraftsData.EVENT_ID + " TEXT, "
            + EventDraftsData.EVENT_TYPE + " TEXT , "
            + EventDraftsData.EVENT_TYPE_NAME + " TEXT , "
            + EventDraftsData.EVENT_TITLE + " TEXT,"
            + EventDraftsData.EVENT_RECEIVER + " TEXT,"
            + EventDraftsData.EVENT_TIME + " TEXT,"
            + EventDraftsData.CONTENT1 + " TEXT,"
            + EventDraftsData.INIT_TITLE1 + " TEXT,"
            + EventDraftsData.CONTENT2 + " TEXT,"
            + EventDraftsData.INIT_TITLE2 + " TEXT,"
            + EventDraftsData.CONTENT3 + " TEXT,"
            + EventDraftsData.INIT_TITLE3 + " TEXT,"
            + EventDraftsData.ATTACHMENT_THUMB_IMAGE + " TEXT,"
            + EventDraftsData.ATTACHMENT_ORI_IMAGE + " TEXT,"
            + EventDraftsData.AUTHOR + " TEXT,"
            + EventDraftsData.ACTIVITY_TIME + " TEXT,"
            + EventDraftsData.END_TIME + " TEXT,"
            + EventDraftsData.IS_QRCODE + " TEXT,"
            + EventDraftsData.ACTIVITY_SITE + " TEXT"
            + ");";


    /**
     * 创建用户表
     */
    private static final String CREATE_USER_MSG = "CREATE TABLE IF NOT EXISTS " +
            UserData.TABLE_NAME + " (" + UserData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + UserData.USER_ID + " TEXT,"
            + UserData.USER_NAME + " TEXT, "
            + UserData.USER_IMG + " TEXT"
            + ");";

    /**
     * 团队联系人的数据
     */
    private static final String CREATE_CONTACT_MSG = "CREATE TABLE IF NOT EXISTS " +
            ContactData.TABLE_NAME + " ( " + ContactData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + ContactData.MY_USER_ID + " TEXT, "
            + ContactData.CONTACT_NAME + " TEXT, "
            + ContactData.CONTACT_PHONE + " TEXT, "
            + ContactData.CONTACT_JOB + " TEXT, "
            + ContactData.CONTACT_GROUP + " TEXT, "
            + ContactData.CONTACT_GROUP_ID + " TEXT "
            + ");";


    /**
     * 人脉圈
     *
     * @param context
     */
    private static final String CREATE_TALK = "CREATE TABLE IF NOT EXISTS " +
            TalkData.TABLE_NAME + " (" + TalkData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + TalkData.TALK_ID + " TEXT, "
            + TalkData.USER_ID + " TEXT, "
            + TalkData.USER_NAME + " TEXT, "
            + TalkData.USER_IMG + " TEXT, "
            + TalkData.TALK_TEXT + " TEXT, "
            + TalkData.TALK_THUMBIMAGE + " TEXT, "
            + TalkData.TALK_ORIIMAGE + " TEXT, "
            + TalkData.TALK_CREATE_TIME + " TEXT, "
            + TalkData.TALK_UPDATE_TIME + " TEXT, "
            + TalkData.TALK_CONTENT_TYPE + " TEXT, "
            + TalkData.TALK_CONTENT_KEY + " TEXT, "
            + TalkData.TALK_COMMENTS + " TEXT, "
            + TalkData.TALK_ISPRAISE + " TEXT, "
            + TalkData.TALK_COMMENTS_LIST + " TEXT, "
            + TalkData.TALK_PRAISES_LIST + " TEXT, "
            + TalkData.TALK_ACTION + " TEXT"
            + ");";

    /**
     * 人脉圈我的消息
     */
    private static final String CREATE_TALK_MY_MESSAGE = "CREATE TABLE IF NOT EXISTS " +
            TalkMyMsgData.TABLE_NAME + " (" + TalkMyMsgData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + TalkMyMsgData.TALK_ID + " TEXT, "
            + TalkMyMsgData.MSG_TYPE + " TEXT, "
            + TalkMyMsgData.MSG_UID + " TEXT, "
            + TalkMyMsgData.MSG_UNAME + " TEXT, "
            + TalkMyMsgData.TALK_TEXT + " TEXT, "
            + TalkMyMsgData.MSG_UIMG + " TEXT, "
            + TalkMyMsgData.MSG_RECV_UID + " TEXT, "
            + TalkMyMsgData.MSG_RECV_UNAME + " TEXT, "
            + TalkMyMsgData.MSG_COMMENT + " TEXT, "
            + TalkMyMsgData.MSG_CTIME + " TEXT, "
            + TalkMyMsgData.TALK_THUMB + " TEXT, "
            + TalkMyMsgData.TALK_UNAME + " TEXT, "
            + TalkMyMsgData.TALK_UIMG + " TEXT, "
            + TalkMyMsgData.TALK_UID + " TEXT, "
            + TalkMyMsgData.TALK_TIME + " TEXT"
            + ");";

    private static final String CREATE_ALARM_WARN = "CREATE TABLE IF NOT EXISTS " +
            AlarmWarnData.TABLE_NAME + " (" + AlarmWarnData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + AlarmWarnData.EVENT_ID + " TEXT, "
            + AlarmWarnData.EVENT_TITLE + " TEXT, "
            + AlarmWarnData.NOTICE + " TEXT, "
            + AlarmWarnData.ALERT_DATETIME + " TEXT, "
            + AlarmWarnData.START_DATETIME + " TEXT, "
            + AlarmWarnData.END_DATETIME + " TEXT, "
            + AlarmWarnData.CREATE_TIME + " TEXT, "
            + AlarmWarnData.UPDATE_TIME + " TEXT, "
            + AlarmWarnData.REMARK + " TEXT, "
            + AlarmWarnData.BOSS_UID + " TEXT, "
            + AlarmWarnData.DELEGATE_USER + " TEXT, "
            + AlarmWarnData.DELEGATE_USERNAME + " TEXT, "
            + AlarmWarnData.ADDRESS + " TEXT"
            + ");";

    private static final String CREATE_CALENDAR = "CREATE TABLE IF NOT EXISTS " +
            CalendarData.TABLE_NAME + " (" + CalendarData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + CalendarData.USER_ID + " TEXT, "
            + CalendarData.YEAR + " TEXT, "
            + CalendarData.MONTH + " TEXT, "
            + CalendarData.DAY + " TEXT, "
            + CalendarData.STATUS + " TEXT, "
            + CalendarData.STATE + " TEXT"
            + ");";


    private static final String CREATE_ATTENDANCE_CALENDAR = "CREATE TABLE IF NOT EXISTS " +
            AttendanceUserCalendarData.TABLE_NAME + " (" + CalendarData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + AttendanceUserCalendarData.ID + " TEXT, "
            + AttendanceUserCalendarData.YEAR + " TEXT, "
            + AttendanceUserCalendarData.MONTH + " TEXT, "
            + AttendanceUserCalendarData.DAY + " TEXT, "
            + AttendanceUserCalendarData.STATUS + " TEXT, "
            + AttendanceUserCalendarData.CHEAT + " TEXT, "
            + AttendanceUserCalendarData.GROUP_ID + " TEXT, "
            + AttendanceUserCalendarData.IS_LEGWORK + " TEXT, "
            + AttendanceUserCalendarData.USER_ID + " TEXT"
            + ");";

    private static final String CREATE_APPROVAL_DATA = "CREATE TABLE IF NOT EXISTS " +
            ApprovalData.TABLE_NAME + " (" + ApprovalData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + ApprovalData.MY_USER_ID + " TEXT, "
            + ApprovalData.USER_ID + " TEXT, "
            + ApprovalData.USER_NAME + " TEXT, "
            + ApprovalData.USER_IMAGE + " TEXT, "

            + ApprovalData.APPROVAL_ID + " TEXT, "
            + ApprovalData.APPROVAL_GROUP_ID + " TEXT, "
            + ApprovalData.APPROVAL_TYPE + " INTEGER, "
            + ApprovalData.APPROVAL_LEAVE_TYPE + " INTEGER, "
            + ApprovalData.APPROVAL_LIST_TYPE + " INTEGER, "
            + ApprovalData.APPROVAL_ADDRESS + " TEXT, "
            + ApprovalData.APPROVAL_START_TIME + " TEXT, "
            + ApprovalData.APPROVAL_END_TIME + " TEXT, "
            + ApprovalData.APPROVAL_START_PART + " INTEGER, "
            + ApprovalData.APPROVAL_END_PART + " INTEGER, "
            + ApprovalData.APPROVAL_DAY + " FLOAT, "
            + ApprovalData.APPROVAL_REASON + " TEXT, "

            + ApprovalData.APPROVE_ADMIN + " TEXT, "
            + ApprovalData.APPROVE_ADMIN_NAME + " TEXT, "
            + ApprovalData.APPROVE_ADMIN_IMAGE + " TEXT, "

            + ApprovalData.APPROVAL_DONE_TIME + " TEXT, "
            + ApprovalData.APPROVAL_TIME + " TEXT, "
            + ApprovalData.APPROVAL_REFUSE_REASON + " TEXT, "
            + ApprovalData.APPROVAL_MONTH + " INTEGER, "
            + ApprovalData.APPROVAL_YEAR + " INTEGER, "
            + ApprovalData.APPROVAL_STATUS + " INTEGER, "
            + ApprovalData.APPROVAL_CANCEL_TIME + " TEXT, "
            + ApprovalData.APPROVAL_CANCEL_DONE_TIME + " TEXT, "
            + ApprovalData.APPROVAL_CANCEL_REASON + " TEXT, "
            + ApprovalData.APPROVAL_CANCEL + " INTEGER, "
            + ApprovalData.APPROVAL_DATES + " TEXT"
            + ");";

    private static final String CREATE_SYSTEM_DATA = "CREATE TABLE IF NOT EXISTS " +
            SystemListData.TABLE_NAME + " (" + SystemListData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + SystemListData.ID + " TEXT, "
            + SystemListData.USER_ID + " TEXT, "
            + SystemListData.PUSH_TITLE + " TEXT, "
            + SystemListData.CREATE_TIME + " TEXT, "
            + SystemListData.EXTRA + " TEXT, "
            + SystemListData.PUSH_TYPE + " TEXT"
            + ");";

    private static final String CREATE_WEEKLY_LIST = "CREATE TABLE IF NOT EXISTS " +
            WeeklyListData.TABLE_NAME + " (" + WeeklyListData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + WeeklyListData.WEEKLY_IDS + " TEXT, "
            + WeeklyListData.WEEK_COUNT + " TEXT, "
            + WeeklyListData.YEAR + " TEXT, "
            + WeeklyListData.MONTH + " TEXT, "
            + WeeklyListData.GROUP_ID + " TEXT"
            + ");";

    private static final String CREATE_WEEKLY_DETAIL = "CREATE TABLE IF NOT EXISTS " +
            WeeklyDetailData.TABLE_NAME + " (" + WeeklyDetailData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + WeeklyDetailData.WEEKLY_ID + " TEXT, "
            + WeeklyDetailData.USER_ID + " TEXT, "
            + WeeklyDetailData.USER_NAME + " TEXT, "
            + WeeklyDetailData.USER_IMG + " TEXT, "
            + WeeklyDetailData.YEAR + " TEXT, "
            + WeeklyDetailData.MONTH + " TEXT, "
            + WeeklyDetailData.WEEK_COUNT + " TEXT, "
            + WeeklyDetailData.CREATE_TIME + " TEXT, "
            + WeeklyDetailData.CONTENT + " TEXT, "
            + WeeklyDetailData.COMMENT + " TEXT, "
            + WeeklyDetailData.ACTION + " TEXT, "
            + WeeklyDetailData.GROUP_ID + " TEXT"
            + ");";

    private static final String CREATE_WEEKLY_UNREAD = "CREATE TABLE IF NOT EXISTS " +
            WeeklyUnReadData.TABLE_NAME + " (" + WeeklyUnReadData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + WeeklyUnReadData.WEEKLY_ID + " TEXT, "
            + WeeklyUnReadData.GROUP_ID + " TEXT, "
            + WeeklyUnReadData.USER_ID + " TEXT, "
            + WeeklyUnReadData.COMMENT_USER_ID + " TEXT, "
            + WeeklyUnReadData.COMMENT_USER_NAME + " TEXT, "
            + WeeklyUnReadData.COMMENT_USER_IMAGE + " TEXT, "
            + WeeklyUnReadData.COMMENT_CONTENT + " TEXT, "
            + WeeklyUnReadData.COMMENT_TIME + " TEXT, "
            + WeeklyUnReadData.WEEKLY_TITLE + " TEXT, "
            + WeeklyUnReadData.WEEKLY_CONTENT + " TEXT"
            + ");";


    private static final String CREATE_CRM_CLUE_LIBRARY_FILTER="CREATE TABLE IF NOT EXISTS " +
            CRMClueLibraryFilterData.TABLE_NAME + " (" + CRMClueLibraryFilterData.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + CRMClueLibraryFilterData.PARENT_ID + " TEXT, "
            + CRMClueLibraryFilterData.PARENT_NAME + " TEXT, "
            + CRMClueLibraryFilterData.PARENT_SELECTED + " INTEGER, "
            + CRMClueLibraryFilterData.CHILD_ID + " TEXT, "
            + CRMClueLibraryFilterData.CHILD_NAME + " TEXT, "
            + CRMClueLibraryFilterData.CHILD_SELECTED + " INTEGER, "
            + CRMClueLibraryFilterData.IF_CHECKBOX + " INTEGER, "
            + CRMClueLibraryFilterData.TYPE + " INTEGER"
            + ");";

    public CloudContactsDBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        mPreferenceUtil = PreferenceUtil.getInstance(context);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_CLOUD_GROUP);
        db.execSQL(CREATE_BLACKLIST_TABLE);
        db.execSQL(CREATE_STATEDATA);
        db.execSQL(CREATE_CHAT_GROUP);
        db.execSQL(CREATE_EVENT);
        db.execSQL(CREATE_EVENT_MODEL);
        db.execSQL(CREATE_EVENT_DRAFTS);
        db.execSQL(CREATE_USER_MSG);
        db.execSQL(CREATE_CONTACT_MSG);
        db.execSQL(CREATE_TALK);
        db.execSQL(CREATE_TALK_MY_MESSAGE);
        db.execSQL(CREATE_ALARM_WARN);
        db.execSQL(CREATE_CALENDAR);
        db.execSQL(CREATE_ATTENDANCE_CALENDAR);
        db.execSQL(CREATE_APPROVAL_DATA);
        db.execSQL(CREATE_SYSTEM_DATA);
        db.execSQL(CREATE_WEEKLY_LIST);
        db.execSQL(CREATE_WEEKLY_DETAIL);
        db.execSQL(CREATE_WEEKLY_UNREAD);
        db.execSQL(CREATE_CRM_CLUE_LIBRARY_FILTER);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + CloudGroupDbo.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + CommunicationRule.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + StateData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + ChatGroupData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + EventData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + EventModelData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + EventDraftsData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + UserData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + ContactData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + TalkData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + TalkMyMsgData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + AlarmWarnData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + CalendarData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + AttendanceUserCalendarData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + ApprovalData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + SystemListData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + WeeklyListData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + WeeklyDetailData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + WeeklyUnReadData.TABLE_NAME + ";");
        db.execSQL("DROP TABLE IF EXISTS " + CRMClueLibraryFilterData.TABLE_NAME + ";");
        onCreate(db);
        if (mPreferenceUtil != null) {
            mPreferenceUtil.save(PreferenceUtil.NEED_WRITE_STATUS, true);
        }
    }
}
